<?php

namespace WxWorkSDK\SendMessage\ApplicationMessage;

class TemplateCard extends SendBase
{
    public array $msgBody;

    public function __construct(array $msgBody)
    {
        $this->msgBody = $msgBody;
    }

    /**
     * @return array
     * @annotation
     */
    public function buildParam(): array
    {
        $postData = [
            "msgtype"                  => "template_card",
            "agentid"                  => $this->agentId,
            "template_card"            => $this->msgBody,
            'enable_duplicate_check'   => $this->enable_duplicate_check,
            'duplicate_check_interval' => $this->duplicate_check_interval,
        ];
        if ($this->toUser) {
            $postData['touser'] = $this->toUser;
        }
        if ($this->toParty) {
            $postData['toparty'] = $this->toParty;
        }
        if ($this->toTag) {
            $postData['totag'] = $this->toTag;
        }
        return $postData;
    }

    /**
     * @return string
     * @annotation
     */
    public function customCheck(): string
    {
        if (empty($this->msgBody)) {
            return "消息体为空";
        }
        return '';
    }
}